< previous page page_575 next page >

Page 575
Placing Information Onscreen
Suppose that you have written a data entry screen using the Data control and bound controls. To display information onscreen, you simply draw bound controls and then set the appropriate data fields for the controls. The display of the information is automatic. If you use Data Access Objects, the process is only slightly more involved. You still use control objects (text boxes, labels, check boxes, and so on) to display the information, but you have to assign the data fields to the correct control properties with each record displayed.
For example, you must assign the contents of a field to a text box's Text property or a Label control's Caption property. When used in this manner, the control objects are typically referred to as unbound controls. One advantage of using unbound controls is that you can use any control to display data, not just the bound controls specifically designated for use with the Data control.
Accessing Information from Database Fields
Information in fields can be accessed through a recordset's Fields collection in one of several ways. For example, any of the following techniques would suffice for retrieving the contents of a field named ThisField in a recordset named rsTest and placing it into a text box named Text1:
Use the field's ordinal position in the Fields collection: Text1.Text = rsTest.Fields(0) (assuming ThisField is the first field in the recordset)
Use the field's name to retrieve it from the Fields collection: Text1.Text = rsTest.Fields("ThisField")
Take advantage of the fact that the Fields collection is the default collection of a recordset: Text1.Text = rsTest("ThisField")
Use the shorthand version of the preceding technique: Text1.Text = rsTest!ThisField
note.gif If a field's name contains spaces, you can enclose the entire name in square brackets, as in Text1.Text = rsTest![longer field name]. square.gif

Displaying Data in the Sample Program
Now you can enhance the sample program by having it actually display the data in the database. If you have followed the instructions so far, your program creates a Database object and a Recordset object by opening the BIBLIO.MDB database and its Titles table. Continue by writing a user-defined sub procedure that displays the ISBN, title, and year published of the current record, as shown in the following steps:
1. Add three text boxes named txtISBN, txtTitle, and txtYear.
2. Add associated Label controls to identify the text boxes.
3. Set the labels' Caption properties appropriately:

 
< previous page page_575 next page >